//
//  LSPayResultVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/8/11.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "LSPayResultVC.h"

@interface LSPayResultVC ()
@property (weak, nonatomic) IBOutlet UIImageView *headImg;
@property (weak, nonatomic) IBOutlet UILabel *cashLabel;
@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *bottomLabel;

@end

@implementation LSPayResultVC

//充值成功
-(void)setCashTypeWithCashSuccess{

    self.cashtype = cashSuccess;

}

//充值失败
-(void)setCashTypeWithCashFailed{
    
    self.cashtype = cashFailed;
    
}

//提现成功
-(void)setCashTypeWithExchangeSuccess{
    
    self.cashtype = exchangeSuccess;
    
}

//提现失败
-(void)setCashTypeWithExchangeFailed{
    
    self.cashtype = exchangeFailed;
    
}

-(void)leftBarButtonItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:YES];
    self.tabBarController.tabBar.hidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    switch (self.cashtype) {
        case cashSuccess:
        {
            self.title = @"充值成功";
            self.headImg.image = [UIImage imageNamed:@"充值成功"];
            
            if (allConstDict) {
                [self presentViewWithAlipaySuccess];
            }
            
            [self sendRequest];
            [LSCoverUserInfo CoverUserInfo];
        }
            break;
            
        case cashFailed:
        {
        
            self.title = @"充值失败";
            self.headImg.image = [UIImage imageNamed:@"充值失败"];
            self.topLabel.text = @"非常抱歉，充值失败！";
            self.bottomLabel.text = @"由于系统本次故障充值失败,请稍后重试!";
        
        }
            break;
            
        case exchangeSuccess:
        {
        
            self.title = @"兑换成功";
            self.headImg.image = [UIImage imageNamed:@"提现-提现成功"];
            self.topLabel.text = @"恭喜您,提现成功！";
            self.bottomLabel.text = @"24小时内到账，请注意查收！";
        
        }
            break;
            
        case exchangeFailed:
        {
        
            self.title = @"兑换失败";
            self.headImg.image = [UIImage imageNamed:@"提现-提现失败"];
            self.topLabel.text = @"非常抱歉，由于本次系统故障，请稍后再试";
            self.bottomLabel.text = @"";
        
        }
            break;
            
        default:
            break;
    }
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
}

#pragma mark - 首页支付通知
-(void)presentViewWithAlipaySuccess{
    
    [LSHttpTool sendHttpData:@"buyProjectDetail_app_pay.im.lensum" params:allConstDict success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        NSLog(@"%@",dicInfo);
        
    } failure:^(NSError *error) {
        
    }];
    
    allConstDict = nil;
    
}

#pragma mark - 请求数据
-(void)sendRequest{
    
    NSMutableDictionary * dic = [NSMutableDictionary  dictionary];
    dic[@"token"] = allConstMemberToken;
    dic[@"userId"] = allConstMemberid;

    
    [LSHttpTool sendHttpData:@"getUserBalance_app_pay.im.lensum" params:dic success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        NSString * balanceStr = [YZBase64 textFromBase64String:dicInfo[@"data"][@"balance"]];
        self.cashLabel.text = [NSString stringWithFormat:@"￥%.2f",[balanceStr floatValue]];
        self.topLabel.text = @"恭喜您，充值成功!";
        self.bottomLabel.text = @"系统到账可能会有一定延迟，返回我的钱包查看明细!";
        
    } failure:^(NSError *error) {

       [self showSingleIconBubble:@"网络连接错误"];
    }];
    
}
@end
